package boot.spring.util;

import boot.spring.config.ServiceException;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.metadata.data.ReadCellData;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.Objects;


/**
 * @Description: Excel 表头校验工具类
 * @Author: dongxin
 * @Date: 2024/6/20
 */
@Slf4j
public class ExcelHeaderValidateUtil {

    /**
     * 导入学生表头长度
     */
    private static final int IMPORT_HEADER_SIZE = 6;

    public static void validateImportStudent(Map<Integer, ReadCellData<?>> headMap) {
        if (CollUtil.isEmpty(headMap) || headMap.size() < IMPORT_HEADER_SIZE) {
            throw new ServiceException("导入文件与模板不符");
        }
        // 校验表头
        if (Objects.equals("票型名称", headMap.get(0).getStringValue())
                && Objects.equals("姓名",headMap.get(1).getStringValue())
                && Objects.equals("证件类型",headMap.get(2).getStringValue())
                && Objects.equals("证件号码",headMap.get(3).getStringValue())
                && Objects.equals("抢票优先级",headMap.get(5).getStringValue())
        ) {
            return;
        }
        throw new ServiceException("导入文件与模板不符");
    }
}
